package com.xiehao.springbootmybaits.controller;

import com.xiehao.springbootmybaits.entity.Student;
import com.xiehao.springbootmybaits.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    StudentService studentService;

    @GetMapping("/{id}")
    public String getStudent(@PathVariable Integer id, Model model){
        Student student = studentService.getStudent(id);
        model.addAttribute(student);
        return "student";
    }
}
